<?php
/**
 * Created by PhpStorm.
 * User: xuho
 * Date: 2020-09-02
 * Time: 17:10
 */

namespace extend\payment;


class FuYouPay extends FuYouBase
{
    public $domain = '';

    // 订单类型：ALIPAY-支付宝，WECHAT-微信，UNIONPAY-银联二维码，WXAPP-微信app,ALIAPP-支付宝app,WXH5-微信h5,ALIH5-支付宝h5,WXBX-微信保险类,ALBX-支付宝保险类,WXXS-微信线上所有交易
    public $orderType = ['1' => 'WECHAT', '2' => 'ALIPAY', '3' => 'UNIONPAY', '4' => 'WXAPP', '5' => 'ALIAPP', '6' => 'WXH5', '7' => 'ALIH5', '8' => 'WXBX', '9' => 'ALBX', '10' => 'WXXS'];

    // 支付类型：JSAPI-公众号支付,GZXS-公众号线上,APP-app支付,FWC-支付宝服务窗,LETPAY-小程序,LPXS-小程序线上,WXBXJS-微信公众号保险类,WXBXLET-微信小程序保险类,WXBXAPP-微信APP保险类,ALBXJS-支付宝服务窗保险类,APPLEPAY-相机扫码,UNIONPAY-云闪付扫码
    public $tradeType = ['1' => 'JSAPI', '2' => 'GZXS', '3' => 'APP', '4' => 'FWC', '5' => 'LETPAY', '6' => 'LPXS', '7' => 'WXBXJS', '8' => 'WXBXLET', '9' => 'WXBXAPP', '10' => 'ALBXJS', '11' => 'APPLEPAY', '12' => 'UNIONPAY'];

    /**
     * 统一下订单，服务窗模式
     * 自定义生成订单方式
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function unifiedOrder($request)
    {
        // 接口类型
        $apiType = "order_create";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/preCreate";


        // 必填数据
        $paramSign["goods_des"] = $request["goods_des"];
        $paramSign["order_amt"] = $request["order_amt"];
        $paramSign["notify_url"] = $request["notify_url"];
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];
        $paramSign["txn_begin_ts"] = date("YmdHis", time());

        // 非必填数据
        $paramSign["openid"] = $request["openid"] ?? "";
        $paramSign["sub_openid"] = $request["sub_openid"] ?? "";
        $paramSign["sub_appid"] = $request["sub_appid"] ?? "";

        $paramSign["goods_detail"] = $request["goods_detail"] ?? "";
        $paramSign["goods_tag"] = $request["goods_tag"] ?? "";
        $paramSign["product_id"] = $request["product_id"] ?? "";
        $paramSign["limit_pay"] = $request["limit_pay"] ?? "";

        $paramSign["reserved_sub_appid"] = $request["reserved_sub_appid"] ?? "";
        $paramSign["reserved_limit_pay"] = $request["reserved_limit_pay"] ?? "";
        $paramSign["reserved_expire_minute"] = $request["reserved_expire_minute"] ?? "";
        $paramSign["reserved_user_creid"] = $request["reserved_user_creid"] ?? "";
        $paramSign["reserved_user_truename"] = $request["reserved_user_truename"] ?? "";
        $paramSign["reserved_user_mobile"] = $request["reserved_user_mobile"] ?? "";
        $paramSign["reserved_bxno_inf"] = $request["reserved_bxno_inf"] ?? "";
        $paramSign["reserved_fy_term_sn"] = $request["reserved_fy_term_sn"] ?? "";
        $paramSign["reserved_fy_term_type"] = $request["reserved_fy_term_type"] ?? "";
        $paramSign["reserved_device_info"] = $request["Reserved_txn_bonus"] ?? "";
        $paramSign["reserved_ali_extend_params"] = $request["reserved_ali_extend_params"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_type']}|{$paramSign['order_amt']}|{$paramSign['mchnt_order_no']}|{$paramSign['txn_begin_ts']}|{$paramSign['goods_des']}|{$paramSign['term_id']}|{$paramSign['term_ip']}|{$paramSign['notify_url']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }


    /**
     * 条码支付，商户扫客户
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function microOrder($request)
    {
        // 接口类型
        $apiType = "order_create";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/micropay";

        $paramSign["order_type"] = $this->orderType[$request["order_type"]];
        $paramSign["goods_des"] = $request["goods_des"];
        $paramSign["order_amt"] = $request["order_amt"];
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["auth_code"] = $request["auth_code"];

        // 非必填数据
        $paramSign["goods_detail"] = $request["goods_detail"] ?? "";
        $paramSign["goods_tag"] = $request["goods_tag"] ?? "";
        // 支付场景：1-条形支付 2-声波支付
        $paramSign["sence"] = $request["sence"] ?? "1";

        $paramSign["reserved_sub_appid"] = $request["reserved_sub_appid"] ?? "";
        $paramSign["reserved_limit_pay"] = $request["reserved_limit_pay"] ?? "";
        $paramSign["reserved_expire_minute"] = $request["reserved_expire_minute"] ?? "";
        $paramSign["reserved_fy_term_id"] = $request["reserved_fy_term_id"] ?? "";
        $paramSign["reserved_expire_minute"] = $request["reserved_expire_minute"] ?? "";
        $paramSign["reserved_user_creid"] = $request["reserved_user_creid"] ?? "";
        $paramSign["reserved_user_truename"] = $request["reserved_user_truename"] ?? "";
        $paramSign["reserved_user_mobile"] = $request["reserved_user_mobile"] ?? "";
        $paramSign["reserved_bxno_inf"] = $request["reserved_bxno_inf"] ?? "";
        $paramSign["reserved_fy_term_type"] = $request["reserved_fy_term_type"] ?? "";
        $paramSign["reserved_fy_term_sn"] = $request["reserved_fy_term_sn"] ?? "";
        $paramSign["reserved_device_info"] = $request["reserved_device_info"] ?? "";
        $paramSign["reserved_ali_extend_params"] = $request["reserved_ali_extend_params"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_type']}|{$paramSign['order_amt']}|{$paramSign['mchnt_order_no']}|{$paramSign['txn_begin_ts']}|{$paramSign['goods_des']}|{$paramSign['term_id']}|{$paramSign['term_ip']}|{$paramSign['auth_code']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);

    }

    /**
     * 订单查询
     * 目前系统支持往前查询3日的交易。即 T-3 到 T 日的交易才能查询到记录。
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function orderQuery($request)
    {
        // 接口类型
        $apiType = "order";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/commonQuery";

        // 必填数据
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_type']}|{$paramSign['mchnt_order_no']}|{$paramSign['term_id']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 退款订单
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function orderRefund($request)
    {
        // 接口类型
        $apiType = "order";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/commonRefund";

        // 必填数据
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];
        $paramSign["refund_order_no"] = $request["refund_order_no"];
        $paramSign["total_amt"] = $request["total_amt"];
        $paramSign["refund_amt"] = $request["refund_amt"];

        // 非必填数据
        $paramSign["operator_id"] = $param["operator_id"] ?? "";
        $paramSign["reserved_fy_term_id"] = $param["reserved_fy_term_id"] ?? "";
        $paramSign["reserved_origi_dt"] = $param["reserved_origi_dt"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_type']}|{$paramSign['mchnt_order_no']}|{$paramSign['refund_order_no']}|{$paramSign['total_amt']}|{$paramSign['refund_amt']}|{$paramSign['term_id']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }


    /**
     * 公众号/服务窗统一下单接口
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function wxOrder($request)
    {
        // 接口类型
        $apiType = "order_create";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/wxPreCreate";

        // 必填数据
        $paramSign["goods_des"] = $request["goods_des"];
        $paramSign["order_amt"] = intval($request["order_amt"]);
        $paramSign["notify_url"] = $request["notify_url"];
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["trade_type"] = $this->tradeType[$request["trade_type"]];

        // 非必填数据
        $paramSign["openid"] = $request["openid"] ?? "";
        $paramSign["sub_openid"] = $request["sub_openid"] ?? "";
        $paramSign["sub_appid"] = $request["sub_appid"] ?? "";
        $paramSign["goods_detail"] = $request["goods_detail"] ?? "";
        $paramSign["goods_tag"] = $request["goods_tag"] ?? "";
        $paramSign["product_id"] = $request["product_id"] ?? "";
        $paramSign["limit_pay"] = $request["limit_pay"] ?? "";
        $paramSign["reserved_expire_minute"] = $request["reserved_expire_minute"] ?? "";
        $paramSign["reserved_fy_term_id"] = $request["reserved_fy_term_id"] ?? "";
        $paramSign["reserved_fy_term_type"] = $request["reserved_fy_term_type"] ?? "";
        $paramSign["reserved_user_creid"] = $request["reserved_user_creid"] ?? "";
        $paramSign["reserved_user_truename"] = $request["reserved_user_truename"] ?? "";
        $paramSign["reserved_user_mobile"] = $request["reserved_user_mobile"] ?? "";
        $paramSign["reserved_bxno_inf"] = $request["reserved_bxno_inf"] ?? "";
        $paramSign["reserved_fy_term_type"] = $request["reserved_fy_term_type"] ?? "";
        $paramSign["reserved_fy_term_sn"] = $request["reserved_fy_term_sn"] ?? "";
        $paramSign["reserved_device_info"] = $request["reserved_device_info"] ?? "";
        $paramSign["reserved_ali_extend_params"] = $request["reserved_ali_extend_params"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['trade_type']}|{$paramSign['order_amt']}|{$paramSign['mchnt_order_no']}|{$paramSign['txn_begin_ts']}|{$paramSign['goods_des']}|{$paramSign['term_id']}|{$paramSign['term_ip']}|{$paramSign['notify_url']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);
        return $this->afterRequest($response, $apiType);
    }

    /**
     * 简版微信小程序下单接口
     * 该接口常应用于商户 APP 内微信支付
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function miniOrder($request)
    {
        // 接口类型
        $apiType = "order_create";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/xcxPreCreate";

        // 必填数据
        $paramSign["notify_url"] = $request["notify_url"];
        $paramSign["order_amt"] = $request["order_amt"];
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];

        // 非必填数据
        $paramSign["sub_openid"] = $request["sub_openid"] ?? "";
        $paramSign["sub_appid"] = $request["sub_appid"] ?? "";
        $paramSign["reserved_fy_term_type"] = $request["reserved_fy_term_type"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_amt']}|{$paramSign['mchnt_order_no']}|{$paramSign['notify_url']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 查询可提现资金信息
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function withdrawAmountQuery($request)
    {
        // 接口类型
        $apiType = "withdraw";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);

        // 接口地址
        $urlApi = "/aggregatePay/queryWithdrawAmt";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['random_str']}|{$paramSign['mchnt_key']}");
        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 查询提现手续费信息
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function feeAmountQuery($request)
    {
        // 接口类型
        $apiType = "withdraw";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);

        // 接口地址
        $urlApi = "/aggregatePay/queryFeeAmt";

        // 必填数据
        $paramSign["amt"] = $request["amt"];

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['amt']}|{$paramSign['random_str']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 发起提现
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function withDraw($request)
    {
        // 接口类型
        $apiType = "withdraw";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/withdraw";

        // 必填数据
        $paramSign["amt"] = $request["amt"];
        $paramSign["fee_amt"] = $request["fee_amt"];
        // 1-未结提现 2-已结提现
        $paramSign["txn_type"] = $request["txn_type"];

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['amt']}|{$paramSign['fee_amt']}|{$paramSign['txn_type']}|{$paramSign['random_str']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);
        return $this->afterRequest($response, $apiType);
    }

    /**
     * 资金划拨查询
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function capitalDetailQuery($request)
    {
        // 接口类型
        $apiType = "settle";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/queryChnlPayAmt";

        // 必填数据
        // 格式 yyyyMMdd
        $paramSign["start_date"] = $request["start_date"];
        $paramSign["end_date"] = $request["end_date"];
        $paramSign["start_index"] = $request["start_index"];
        $paramSign["end_index"] = $request["end_index"];

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['start_date']}|{$paramSign['end_date']}|{$paramSign['start_index']}|{$paramSign['end_index']}|{$paramSign['random_str']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 扫码 wap/app 下单
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function scanOrder($request)
    {
        // 接口类型
        $apiType = "order_create";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/wapPreCreate";

        // 必填数据
        $paramSign["goods_des"] = $request["goods_des"];
        $paramSign["order_amt"] = $request["order_amt"];
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];
        $paramSign["trade_type"] = $this->tradeType['3'];
        $paramSign["notify_url"] = $request['notify_url'];

        // 非必填数据
        $paramSign["goods_detail"] = $request["goods_detail"] ?? "";
        $paramSign["goods_tag"] = $request["goods_tag"] ?? "";
        $paramSign["reserved_device_info"] = $request["reserved_device_info"] ?? "";
        $paramSign["front_notify_url"] = $request["front_notify_url"] ?? "";
        $paramSign["reserved_sub_appid"] = $request["reserved_sub_appid"] ?? "";
        $paramSign["reserved_limit_pay"] = $request["reserved_limit_pay"] ?? "";
        $paramSign["reserved_fy_term_id"] = $request["reserved_fy_term_id"] ?? "";
        $paramSign["reserved_expire_minute"] = $request["reserved_expire_minute"] ?? "";
        $paramSign["reserved_user_creid"] = $request["reserved_user_creid"] ?? "";
        $paramSign["reserved_user_truename"] = $request["reserved_user_truename"] ?? "";
        $paramSign["reserved_user_mobile"] = $request["reserved_user_mobile"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_type']}|{$paramSign['trade_type']}|{$paramSign['order_amt']}|{$paramSign['mchnt_order_no']}|{$paramSign['txn_begin_ts']}|{$paramSign['goods_des']}|{$paramSign['term_id']}|{$paramSign['term_ip']}|{$paramSign['notify_url']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 历史订单查询接口
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function historyOrderQuery($request)
    {
        // 接口类型
        $apiType = "order";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/hisTradeQuery";

        // 必填数据
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];

        // 非必填数据
        $paramSign["trade_dt"] = $request["trade_dt"] ?? '';
        $paramSign["channel_order_id"] = $request["channel_order_id"] ?? '';
        $paramSign["transaction_id"] = $request["transaction_id"] ?? '';

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['order_type']}|{$paramSign['term_id']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 退款查询接口
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function refundQuery($request)
    {
        // 接口类型
        $apiType = "order";
        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/refundQuery";

        // 必填数据
        $paramSign["refund_order_no"] = $request["refund_order_no"];

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['refund_order_no']}|{$paramSign['term_id']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 关闭订单接口
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function orderClose($request)
    {
        // 接口类型
        $apiType = "order";

        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/closeOrder";

        // 必填数据
        $paramSign["mchnt_order_no"] = $request['mchnt_order_no'];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];

        // 非必填数据
        $paramSign["sub_appid"] = $request["sub_appid"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['mchnt_order_no']}|{$paramSign['order_type']}|{$paramSign['term_id']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }


    /**
     * 撤销订单
     * 只支持条码支付撤销
     * @param $request
     * @return mixed
     * @throws \Exception
     */
    public function orderCancel($request)
    {
        // 接口类型
        $apiType = "order";
        // 获取支付参数
        $paramSign = $this->beforeRequest($request, $apiType);
        // 接口地址
        $urlApi = "/aggregatePay/cancelOrder";

        // 必填数据
        $paramSign["mchnt_order_no"] = $request["mchnt_order_no"];
        $paramSign["cancel_order_no"] = $request["cancel_order_no"];
        $paramSign["order_type"] = $this->orderType[$request["order_type"]];

        // 非必填数据
        $paramSign["operator_id"] = $param["operator_id"] ?? "";
        $paramSign["reserved_fy_term_id"] = $param["reserved_fy_term_id"] ?? "";

        $paramSign['sign'] = md5("{$paramSign['mchnt_cd']}|{$paramSign['mchnt_order_no']}|{$paramSign['order_type']}|{$paramSign['cancel_order_no']}|{$paramSign['term_id']}|{$paramSign['random_str']}|{$paramSign['version']}|{$paramSign['mchnt_key']}");

        $response = $this->sendRequest($urlApi, $paramSign);

        return $this->afterRequest($response, $apiType);
    }

    /**
     * 请求前操作
     * @param array $request
     * @param string $type
     *  共4种类型 ： order_create、order、withdraw、settle
     * @return mixed
     */
    public function beforeRequest($request = [], $type = "order")
    {
        $this->domain = $request['domain'];
        // 商户号
        $paramSign["mchnt_cd"] = $request["mchnt_cd"];
        // 随机字符串
        $paramSign["random_str"] = nonceStr();
        // 密钥
        $paramSign['mchnt_key'] = $request['mchnt_key'];

        // 判断是否为订单类型
        if (strpos($type, "order") !== false) {
            // 版本
            $paramSign["version"] = $request['version'];
            // 终端号(没有真实终端号统一填88888888)
            $paramSign["term_id"] = $request['term_id'];

            // 判断是否为创建订单接口
            if ($type == "order_create") {
                // 附加数据
                $paramSign["addn_inf"] = "";
                // 交易时间
                $paramSign["txn_begin_ts"] = date("YmdHis", time());
                // 货币类型
                $paramSign["curr_type"] = $request['curr_type'];
                // ip 地址
                $paramSign["term_ip"] = $request["term_ip"];
            }
        }

        return $paramSign;
    }


    /**
     * 发送请求
     * @param $url
     * @param $paramSign
     * @return string
     * @throws \Exception
     */
    public function sendRequest($url, $paramSign)
    {
        // 链接
        $url = $this->domain . $url;
        $paramSign = json_encode($paramSign, JSON_UNESCAPED_UNICODE);
        $response = postRequest($url, $paramSign, ['Content-Type: application/json; charset=utf-8']);
        return $response;
    }


    /**
     * 返回结果
     * @param $response
     * @param string $responseType
     *  共4种类型 ： order_create、order、withdraw、settle
     * @return mixed
     * @throws \Exception
     */
    public function afterRequest($response, $responseType)
    {
        $response = json_decode($response, true);

        if (strpos($responseType, "order") !== false) {
            // 订单类型
            if ($response["result_code"] == "000000") {
                $result["status"] = "1";
                $result["msg"] = "success";
                $result["data"] = $response;
            } else {
                $result["status"] = "0";
                $result["msg"] = $response["result_msg"];
            }
        } else if ($responseType == "withdraw") {
            // 提现类型
            if ($response["result_code"] == "SUCCESS") {
                $result["status"] = "1";
                $result["msg"] = "success";
                $result["data"] = $response;
            } else {
                $result["status"] = "0";
                $result["msg"] = $response["return_msg"];
            }
        } else {
            $result["status"] = "1";
            $result["msg"] = "success";
            $result["data"] = $response;
        }
        return $result;
    }

}